import yaml
from common.tools import join_path, get_project_path


class yaml_utils:
    def __init__(self):
        project_path = get_project_path()
        with open(project_path + join_path(["config", "data.yaml"], prefix_sep=True), "r", encoding="utf-8") as f:
            self.f = yaml.safe_load(f)  # 使用 safe_load 替代

    def get_username(self, user):
        return self.f["user"][f"{user}"]["username"], self.f["user"][f"{user}"]["password"]

    def get_url(self):
        return self.f["url"]

    def get_mysql_config(self):
        return self.f["mysql"]


if __name__ == '__main__':
    yaml_utils = yaml_utils()
    print(yaml_utils.get_url())
    print(yaml_utils.get_username("admin"))
    print(yaml_utils.get_mysql_config())